package cn.ccew.sys.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.sf.json.JSONString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import cn.ccew.common.base.model.BaseEntity;

/**
 * @类功能说明：资源
 * @类修改者：
 * @修改日期：
 * @修改说明：
 * @公司：春城1网
 * @作者：李兴建
 * @创建时间：2013-10-1 下午12:31:19
 * @版本：V1.0
 */

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "sys_resources")
public class SysResources extends BaseEntity /* implements JSONString */{

	public SysResources(String rsName, int priority, SysResources parent) {
		super();
		this.setPriority(priority);
		this.rsName = rsName;
		this.parent = parent;
	}

	public SysResources() {
		super();
	}

	/**
	 * 资源名称
	 */
	private String rsName;
	// text=rsName
	@Transient
	private String text;

	/**
	 * 功能描述，功能和调用方法识别名称
	 */
	private String rsFunctionName;
	/**
	 * 功能js路径
	 */
	private String rsFunctionJsPath;
	/**
	 * 资源图标
	 */
	private String rsImage;
	/**
	 * 资源描述
	 */
	private String rsDescription;

	/**
	 * 是否是叶子节点，不做持久
	 */
	@Transient
	private boolean leaf;
	/**
	 * 自定义资源标识【扩展】
	 */
	private String rsCustomMark;

	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@ManyToOne
	@JoinColumn(name = "rs_pid")
	private SysResources parent;

	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@OneToMany(mappedBy = "parent")
	private List<SysResources> children = new ArrayList<SysResources>();

	/**
	 * 扩展字段，不持久
	 */
	@Transient
	private List<BaseEntity> expandlist;

	public String getRsName() {
		return rsName;
	}

	public String getText() {
		return rsName;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setRsName(String rsName) {
		this.rsName = rsName;
	}

	public String getRsImage() {
		return rsImage;
	}

	public List<BaseEntity> getExpandlist() {
		return expandlist;
	}

	public void setExpandlist(List<BaseEntity> expandlist) {
		this.expandlist = expandlist;
	}

	public void setRsImage(String rsImage) {
		this.rsImage = rsImage;
	}

	public SysResources getParent() {
		return parent;
	}

	public void setParent(SysResources parent) {
		this.parent = parent;
	}

	public List<SysResources> getChildren() {
		return children;
	}

	public void setChildren(List<SysResources> children) {
		this.children = children;
	}

	public String getRsDescription() {
		return rsDescription;
	}

	public void setRsDescription(String rsDescription) {
		this.rsDescription = rsDescription;
	}

	public boolean getLeaf() {
		if (children.size() < 1) {
			return true;
		}
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public String getRsFunctionName() {
		return rsFunctionName;
	}

	public void setRsFunctionName(String rsFunctionName) {
		this.rsFunctionName = rsFunctionName;
	}

	public String getRsFunctionJsPath() {
		return rsFunctionJsPath;
	}

	public void setRsFunctionJsPath(String rsFunctionJsPath) {
		this.rsFunctionJsPath = rsFunctionJsPath;
	}

	public String getRsCustomMark() {
		return rsCustomMark;
	}

	public void setRsCustomMark(String rsCustomMark) {
		this.rsCustomMark = rsCustomMark;
	}

	/*
	 * @Override public String toJSONString() { return "{rsName:'" + rsName +
	 * "', rsFunctionName:'" + rsFunctionName + "', rsFunctionJsPath:'" +
	 * rsFunctionJsPath + "', rsImage:'" + rsImage + "', rsDescription:'" +
	 * rsDescription + "', leaf:'" + leaf + "', rsCustomMark:'" + rsCustomMark +
	 * "', children:" + children + ", id:'" + getId() + "', priority:'" +
	 * getPriority() + "'}"; }
	 */

}
